home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11674 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: svnews.ubinet.ubs.com!ubszh!ian.johnston@ubs.com
  2. From: gzhjis@ubszh.net.ch (Ian Johnston (by ubsswop))
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: works in Borland but not in Microsuck Visual C++
  5. Date: 15 Mar 1996 17:02:05 GMT
  6. Organization: UBS
  7. Distribution: world
  8. Message-ID: <4ic7qd$2fa@ubszh.fh.zh.ubs.com>
  9. References: <4ia6h8$jes@news.vanderbilt.edu>
  10. NNTP-Posting-Host: nol2179.fh.zh.ubs.com
  11.  
  12. In article <4ia6h8$jes@news.vanderbilt.edu>, haseltbt@ctrvax.vanderbilt.edu (Bennett Haselton) writes:
  13.  
  14. |>     Dear Abby,
  15. |> 
  16. |>         The following program was written in completely standard C++ 
  17. |> and should be portable across platforms.  However, it only performs as 
  18. |> expected (i.e. sends two copies of 4 to the standard out stream) in Borland 
  19. |> C++; when compiled in MicroSUCK Visual C++, it outputs 4 followed by a random 
  20. |> integer in the thousands.
  21. |> 
  22. |> #include <iostream.h>
  23. |> 
  24. |> struct person {
  25. |>     int age;
  26. |> };
  27. |> 
  28. |> struct person* matchPerson( struct person* psnPtr )
  29. |> {
  30. |>     struct person* ansPtr;
  31. |>     ansPtr->age = psnPtr->age;
  32. |>     cout << ansPtr->age;
  33. |>     cout << ansPtr->age;
  34. |>     return ansPtr;                         
  35. |> };
  36. |> 
  37. |> void main()
  38. |> {
  39. |>     struct person myperson;
  40. |>     myperson.age = 4;
  41. |>     struct person* k = matchPerson( &myperson );
  42. |> }
  43. |> 
  44. |> i was using version 1.0 of Visual C++; i have no knowledge of whether later 
  45. |> Microsuck compilers are capable of handling a program like this properly.  
  46. |> Please avoid buying their products whenever possible if you have not already 
  47. |> resolved to do so.
  48. |>     Is there a further explanation of this anomaly which i did not come 
  49. |> across?  As usual, great Microsuck jokes will be mailed to anyone who can 
  50. |> help.  Thanks!
  51.  
  52. The explanation could be that your code is completely wrong.
  53.  
  54. Try it on a UNIX system, say, and see if it blows up.
  55.  
  56. Ian
  57.  
  58.